<template>
  <NewCard title="收银台" isright="isright">
    <!-- <template slot="right">
      <DownTime @EventTimeIsUp="TimeIsUp" :time="orderinfo.minutes"> </DownTime
      >后结束订单
    </template> -->
     <template slot="right">
      <span class="hintRight"
        >请在 {{ minute }}:{{ second }} 内完成支付，超时订单自动关闭</span
      >
    </template>
    <div class="pay pd30">
      <div class="pay_main">
        <el-row>
          <div class="infomoneny">
            <h3>{{ firstName }}-{{ secondaryName }}-{{ threeName }}</h3>
            <p>发送格式：{{receiveFormat}}PDF</p>
            <p>应付问金：{{ amount }}</p>
          </div>
          <el-col :span="12" :md="24">
            <p class="inputTitle">接收信息</p>
            <el-input v-model="receiveEmail" placeholder="请输入邮箱">
              <!-- <button slot="suffix" class="acceptEmail">换绑邮箱</button> -->
            </el-input>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <Compay ref="compay" :orderinfo="orderinfo"></Compay>
          </el-col>
        </el-row>
      </div>
      <div class="payBtn">
        <p>
          应付问金：<span>{{ amount }}</span>
        </p>
        <el-button round @click="askGoldPay">立即支付</el-button>
      </div>
    </div>
  </NewCard>
</template>

<script>
import DownTime from "@/components/downTime/index.vue";
import { timestampConversion, changeType } from "@/wss/utils/wss.js";
import NewCard from "@/wss/components/newCard.vue";
import Compay from "@/BMViews/components/Compay/index.vue";
import { getDepositVoucherPayApi } from "@/BMViews/api/financial/deposit.js";
import { downloadfun } from "@/wss/utils/wss.js";
import {
  getDocMailEmailApi,
  getOverallDownloadPdfApi,
} from "@/BMViews/api/doc/mail.js";

export default {
  name: "Pay",
  props: {
    // orderinfo: {
    //   type: Object,
    //   default: () => {
    //     return {};
    //   },
    // },
    getConsumptionapilistfn: {
      type: Function,
      default: () => {},
    },
  },
  components: { NewCard, Compay, DownTime },
  data() {
    return {
      // 消费订单参数对象
      orderinfo: { id: "", amount: "" },
      firstName: "",
      secondaryName: "",
      receiveFormat:"",//文本格式
      threeName: "",
       minutes: 15, //分
      seconds: 0, //，秒
      isright: true, //显示时间提示支付
      receiveEmail: this.$store.state.user.email,
      activeName: "askGold", //默认显示问金支付
      amount: "",
      circleUrl:
        "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png", //头像
      askRadio: "2",
    };
  },
  mounted() {
    this.$bus.$on("payinfo", (e, i, z) => {
    
      this.firstName = i;
      this.secondaryName = z;
      this.threeName = e.title;
      this.amount = e.amount;
      this.orderinfo.amount = e.amount;
      this.amount = e.amount;
      this.orderinfo.id = e.order;
    });
     this.countdown();
     this.$bus.$on("hidePayBtn", this.handleClick);
  },
  computed: {
    //计算时间
    second() {
      return this.num(this.seconds);
    },
    minute() {
      return this.num(this.minutes);
    },
  },

  watch: {
    //监听时间
    second: {
      handler(newVal) {
        this.num(newVal);
      },
    },
    minute: {
      handler(newVal) {
        this.num(newVal);
      },
    },
  },
  methods: {
    TimeIsUp() {},
    // 问金支付
    async askGoldPay() {
      let circleId = this.$refs.compay.getCirecleDefaultPay();
      let { code, msg } = await getDepositVoucherPayApi({
        circleId,
        orderId: this.orderinfo.id,
        email:this.receiveEmail
      });
      if (code != 200) return;
      this.$message({
        message: msg,
        type: "success",
      });
      // this.getConsumptionapilistfn();
      this.$emit("completePay");
    },
    //获取到对应的合同报告
      //倒计时
    num(n) {
      return n < 10 ? "0" + n : "" + n;
    },
    countdown() {
      var _this = this;
      var time = window.setInterval(function () {
        if (_this.seconds === 0 && _this.minutes !== 0) {
          _this.seconds = 59;
          _this.minutes -= 1;
        } else if (_this.minutes === 0 && _this.seconds === 0) {
          _this.seconds = 0;
          window.clearInterval(time);
          _this.changes();
        } else {
          _this.seconds -= 1;
        }
      }, 1000);
    },
    // / 如果是扫码支付就隐藏立即支付
    handleClick(tab) {
      if (tab == "scanQr") {
        this.btnpay = false;
      } else {
        this.btnpay = true;
      }
    },
     //返回推荐页面
    changes() {
      this.$bus.$emit("showFeatured", 0);
    },
    
  },
  
  filters: {
    switchType(value) {
      return changeType(value);
    },
  },
};
</script>

<style scoped>
.hintRight {
  font-size: 12px;
  color: #999;
}
::v-deep .el-card__body {
  position: relative;
}
ul,
p {
  list-style: none;
  margin: 0;
  padding: 0;
}
.pd30 {
  padding: 0 30px;
}
/* 支付信息 */
.pay_main {
  margin-bottom: 70px;
  margin-top: 15px;
}
.pay_main .el-card {
  border-radius: 12px;
}
::v-deep .pay_main .el-card__body {
  padding: 20px;
}
.pay_main h3 {
  margin: 0;
  margin-bottom: 12px;
  font-size: 16px;
  color: #333;
  font-weight: bold;
}
.pay_main p {
  font-size: 14px;
  color: #999;
  margin: 0;
  line-height: 24px;
}
.pay_main .el-row {
  margin-top: 15px;
}
::v-deep .pay_main .el-row .el-input__inner {
  border-radius: 8px;
  height: 44px;
  line-height: 44px;
}
.pay_main .el-row .acceptEmail {
  border: 0;
  padding: 5px 0;
  margin: 7px 0;
  margin-right: 10px;
  font-size: 14px;
  color: #bababa;
  background: #fff;
  cursor: pointer;
}
.pay_main .el-row .acceptEmail:hover {
  color: #f87a23;
}
.pay_main .inputTitle {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin-bottom: 15px;
}
.pay_main .inputTitle span {
  font-size: 14px;
  color: #999;
  font-weight: 400;
}
::v-deep .pay_main .el-tabs__header {
  border: 0;
  margin-bottom: 24px;
}
::v-deep .pay_main .el-tabs__nav {
  width: 100%;
  display: flex;
  justify-content: space-between;
  border: 0;
}
::v-deep .pay_main .el-tabs__item {
  width: 49%;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  font-weight: bold;
  border: 0;
  background-color: #fafafa;
}
::v-deep .pay_main .el-tabs__item.is-active {
  background-color: #f1f3ff;
  color: #39486f;
}
::v-deep .pay_main .el-tabs__item:hover {
  color: #39486f;
}

/* 内容详情列表 */
.detailList {
  border-bottom: 1px solid #ecedf0;
  padding-bottom: 15px;
  margin-bottom: 30px;
}
.detailList li {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 15px;
}
.detailList li > span {
  display: block;
  width: 17%;
  font-size: 14px;
  color: #999;
}
.detailList li .detailPage {
  width: 83%;
}
.detailList li .detailPage > p {
  width: 100%;
  font-size: 14px;
  color: #222;
}

/* 支付 */
.askGold {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
}
.askGold li {
  display: flex;
  margin-bottom: 24px;
}
.askGold li .el-avatar {
  margin-right: 14px;
}
.askGold .askInfo h3 {
  margin-bottom: 5px;
  font-size: 16px;
  color: #333;
}
.askGold .askInfo {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #ecedf0;
  padding-bottom: 24px;
}
.askGold .askInfo p {
  font-size: 12px;
  color: #666;
}
.askGold .askInfo button {
  color: #39486f;
  border-color: #39486f;
  padding: 5px 15px;
}
::v-deep .askInfo .el-radio__label {
  display: none;
}
::v-deep .askInfo .el-radio .el-radio__inner {
  width: 24px;
  height: 24px;
  border-color: #bbbbbb;
  background: #fff;
}
::v-deep .askInfo .el-radio .is-disabled .el-radio__inner {
  background: #f2f2f2;
}
::v-deep .askInfo .el-radio .is-checked .el-radio__inner {
  border-color: #f87a23;
  background: #f87a23;
}
::v-deep .askInfo .el-radio__input.is-checked .el-radio__inner::after {
  content: "";
  width: 11px;
  height: 7px;
  border: 3px solid white;
  border-top: transparent;
  border-right: transparent;
  text-align: center;
  display: block;
  position: absolute;
  top: 6px;
  left: 5px;
  vertical-align: middle;
  transform: rotate(-45deg);
  border-radius: 0px;
  background: none;
}
.payBtn {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 9;
  width: 100%;
  background-color: #fff;
  border-top: 1px solid #ecedf0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 30px;
}
.pay .infomoneny {
  padding: 10px;
  border: 1px solid #ecedf0;
  border-radius: 5px;
  margin-bottom: 20px;
}
.payBtn p {
  margin: 0;
  font-size: 14px;
  font-weight: bold;
}
.payBtn p > span {
  color: #f87a23;
  font-size: 16px;
}
.payBtn .el-button {
  background-color: #f87a23;
  border-color: #f87a23;
  color: #fff;
  font-size: 14px;
  padding: 10px 50px;
}
.payBtn .el-button:hover {
  opacity: 0.9;
}

.scanQr {
  text-align: center;
}
.scanQr img {
  width: 150px;
}
.scanQr p {
  color: #f87a23;
  font-size: 18px;
  font-weight: bold;
}
.scanQr span {
  font-size: 12px;
  color: #999;
}

@media (max-width: 1120px) {
  ::v-deep .top .right{
    flex: 2;
  }
  ::v-deep .pay_main .el-card__body{
    padding: 12px 20px !important;
  }

  .pay_main .el-row{
    margin-top: 30px;
  }
  .pay_main .el-row .el-row{
    margin-top: 0px;
  }
}
</style>